﻿package mortal.game.view.collect
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class CollectWindow extends Window
    {
        protected var _bg:ScaleBitmap;
        protected const rewardItemCode:int = 120100334;
        private static var _instance:CollectWindow;

        public function CollectWindow(param1:ILayer = null)
        {
            super(param1);
            setSize(280, 300);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_4:String = null;
            var _loc_5:Array = null;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 280, 300, this, ImagesConst.ToolTipBgLan);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.collectTitle, 72, 20, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.collectTips, 120, 60, this));
            var _loc_1:* = UIFactory.getUICompoment(BaseItem, 34, 63, this);
            _loc_1.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            _loc_1.itemCode = this.rewardItemCode;
            pushUIToDisposeVec(_loc_1);
            pushUIToDisposeVec(UIFactory.bg(18, 155, 240, 2, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(UIFactory.bg(18, 227, 240, 2, this, ImagesConst.SplitLine));
            var _loc_2:* = new ItemData(this.rewardItemCode);
            if (ItemsUtil.isGiftBag(_loc_2) && (_loc_2.itemInfo as ItemGiftBagInfo).itemList1)
            {
                _loc_4 = "";
                _loc_5 = (_loc_2.itemInfo as ItemGiftBagInfo).itemList1.split("&");
                _loc_6 = [];
                _loc_7 = _loc_5.length;
                _loc_8 = 0;
                while (_loc_9 < _loc_7)
                {
                    
                    if (_loc_5[_loc_9])
                    {
                        _loc_6 = (_loc_5[_loc_9] as String).split("#");
                        _loc_10 = _loc_6[1];
                        _loc_11 = _loc_6[2];
                        _loc_1 = UIFactory.getUICompoment(BaseItem, 35 + _loc_8 * 55, 170, this);
                        _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 5, 5);
                        if (_loc_6[1] < 1000)
                        {
                            _loc_1.toolTipData = GameDefConfig.instance.getEPrictUnitName(_loc_6[1]) + _loc_11;
                        }
                        if (_loc_6[0] == 3)
                        {
                            _loc_1.itemCode = _loc_10;
                            _loc_1.amount = _loc_11;
                            pushUIToDisposeVec(_loc_1);
                            _loc_8++;
                        }
                        else if (_loc_6[0] == 2)
                        {
                            _loc_1.source = GlobalClass.getBitmap(GameDefConfig.instance.getEPrictUnitImg(_loc_10));
                            _loc_1.amount = _loc_11;
                            pushUIToDisposeVec(_loc_1);
                            _loc_8++;
                        }
                    }
                    _loc_9++;
                }
            }
            var _loc_3:* = UIFactory.gLoadingButton(ImagesConst.GotoCollect_upSkin, 87, 241, 108, 44, this);
            _loc_3.configEventListener(MouseEvent.CLICK, this.onClickCollect);
            pushUIToDisposeVec(_loc_3);
            return;
        }// end function

        private function onClickCollect(event:MouseEvent) : void
        {
            StoreUpUtil.downloadToDesktop(this.downloadCallBack);
            return;
        }// end function

        private function downloadCallBack() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CollectGame));
            return;
        }// end function

        public static function get instance() : CollectWindow
        {
            if (!_instance)
            {
                _instance = new CollectWindow;
            }
            return _instance;
        }// end function

    }
}
